// 员工管理相关接口
import request from '@/utils/request'

/**
 * 员工登录
 * @param {Object} data - 登录信息 {username, password}
 * @returns {Promise}
 */
export const employeeLogin = (data) => {
  return request({
    url: '/admin/employee/login',
    method: 'post',
    data
  })
}

/**
 * 员工退出登录
 * @returns {Promise}
 */
export const employeeLogout = () => {
  return request({
    url: '/admin/employee/logout',
    method: 'post',
    data: {}
  })
}

/**
 * 员工分页查询
 * @param {Object} params - 查询参数 {name, page, pageSize}
 * @returns {Promise}
 */
export const getEmployeeList = (params) => {
  return request({
    url: '/admin/employee/page',
    method: 'get',
    params
  })
}

/**
 * 新增员工
 * @param {Object} data - 员工信息
 * @returns {Promise}
 */
export const addEmployee = (data) => {
  return request({
    url: '/admin/employee',
    method: 'post',
    data
  })
}

/**
 * 编辑员工信息
 * @param {Object} data - 员工信息
 * @returns {Promise}
 */
export const updateEmployee = (data) => {
  return request({
    url: '/admin/employee',
    method: 'put',
    data
  })
}

/**
 * 根据id查询员工
 * @param {Number} id - 员工id
 * @returns {Promise}
 */
export const getEmployeeById = (id) => {
  return request({
    url: `/admin/employee/${id}`,
    method: 'get'
  })
}

/**
 * 启用、禁用员工账号
 * @param {Number} id - 员工id
 * @param {Number} status - 状态(1:启用, 0:禁用)
 * @returns {Promise}
 */
export const updateEmployeeStatus = (id, status) => {
  return request({
    url: `/admin/employee/status/${status}`,
    method: 'post',
    params: { id }
  })
}

/**
 * 修改密码
 * @param {Object} data - 密码信息 {empId, oldPassword, newPassword}
 * @returns {Promise}
 */
export const updatePassword = (data) => {
  return request({
    url: '/admin/employee/editPassword',
    method: 'put',
    data
  })
}

/**
 * 删除员工
 * @param {Number} id - 员工id
 * @returns {Promise}
 */
export const deleteEmployee = (id) => {
  return request({
    url: `/admin/employee/${id}`,
    method: 'delete'
  })
}